package com.cjkj.common.utils;

import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;

import java.io.IOException;
import java.net.URI;

public class HttpSMS {
    public static String getSendSMS(String mobile,Integer code) {
        String url="http://118.31.9.10:8088/sms.aspx";
        String param="?action=send&userid=1541&account=cqcjkj&password=szqxt@800";
        // 创建Httpclient对象
        CloseableHttpClient httpclient = HttpClients.createDefault();

        String resultString = "";
        CloseableHttpResponse response = null;
        String content="【昶健科技】尊敬的用户，您的验证码是："+code+"，请你在5分钟内输入。请勿告诉其他人。";

        param+="&mobile="+mobile+"&content="+content+"&sendTime=&extno=";
        try {
            // 创建uri
            URIBuilder builder = new URIBuilder(url+param);
            URI uri = builder.build();
            // 创建http GET请求
            HttpGet httpGet = new HttpGet(uri);

            // 执行请求
            response = httpclient.execute(httpGet);
            // 判断返回状态是否为200
            if (response.getStatusLine().getStatusCode() == 200) {
                resultString = EntityUtils.toString(response.getEntity(), "UTF-8");
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            try {
                if (response != null) {
                    response.close();
                }
                httpclient.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return resultString;
    }

}
